package com.lkd.config;

import com.lkd.service.LoginService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class LoginConfig implements ApplicationContextAware {
    //key:LoginType Dengluleixing   eg:VMSystem.LOGIN_ADMIN
    //value:bean  eg:adminLoginServiceImpl
    private Map<Integer,LoginService> resultMap = new HashMap();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //key: bean名字  eg:"adminLoginServiceImpl"
        //value: bean   eg:adminLoginServiceImpl
        Map<String, LoginService> beansOfType = applicationContext.getBeansOfType(LoginService.class);
        beansOfType.values().forEach(each->{
            resultMap.put(each.getLoginType(),each);
        });
    }

    public LoginService getLoginByLoginType(Integer loginType){
        return resultMap.get(loginType);
    }
}
